
//
//  YZNetworkManager+Trade.m
//  YZMicroStock
//
//  Created by wangminhong on 16/4/13.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZClient+Trade.h"
#import "NSNumber+Utils.h"

@implementation YZNetworkManager (Trade)

- (void)td_getConfigureDataSuccess:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_CONFIGURE_DATA parameters:@{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE} success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

//ylb
- (void)td_getYLBConfigureDataSuccess:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_YLBCONFIGURE_DATA parameters:@{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE} success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}



- (void)td_getLimitStockListSuccess:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    [self.mainNetwork cq_noCacheGET:URL_FOR_FETCH_LIMIT_STOCK_LIST parameters:@{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE} success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}


- (void)td_submitTradeWithStockCode:(NSString *)stockCode andMoney:(NSString *)money andLever:(NSInteger)lever andQuitGain:(NSString *)quitGain andQuitLoss:(NSString *)quitLoss andPrincipal:(NSString *)principal andServiceCharge:(NSString *)serviceCharge andStockCount:(NSInteger)stockCount andToken:(NSString *)token andUseRedpack:(BOOL)useRedpack success:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure{
    
    NSDictionary *param = @{@"money":money,
                            @"lever":@(lever),
                            @"quitLoss":quitLoss,
                            @"quitGain":quitGain,
                            @"principal":principal,
                            @"serviceCharge":serviceCharge,
                            @"stockCode":stockCode,
                            @"volumeOrder":@(stockCount),
                            @"token":token,
                            @"useTip":@(useRedpack),
                            COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCachePOST:URL_FOR_SUBMIT_TRADE parameters:param success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_submitTradeYLBWithStockCode:(NSString *)stockCode andMoney:(NSString *)money andLever:(NSInteger)lever andQuitGain:(NSString *)quitGain andQuitLoss:(NSString *)quitLoss andPrincipal:(NSString *)principal andServiceCharge:(NSString *)serviceCharge andStockCount:(NSInteger)stockCount andToken:(NSString *)token andUseRedpack:(BOOL)useRedpack success:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure{
    
    NSDictionary *param = @{@"money":money,
                            @"lever":@(lever),
                            @"quitLoss":quitLoss,
                            @"quitGain":quitGain,
                            @"principal":principal,
                            @"serviceCharge":serviceCharge,
                            @"stockCode":stockCode,
                            @"volumeOrder":@(stockCount),
                            @"token":token,
                            @"useTip":@(false),
                            COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCachePOST:URL_FOR_SUBMIT_TRADEYLB parameters:param success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}


//- (void)td_submitTradeWithStockCode:(NSString *)stockCode andMoney:(NSString *)money andLever:(NSInteger)lever andQuitGain:(NSString *)quitGain andQuitLoss:(NSString *)quitLoss andPrincipal:(NSString *)principal andServiceCharge:(NSString *)serviceCharge andStockCount:(NSInteger)stockCount andToken:(NSString *)token success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
//    
//
//}

- (void)td_fetchSaleTradeListWithPage:(NSInteger)page andPageSize:(NSInteger)pageSize andTimeEnd:(NSString *)timeEnd success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"page":@(page),
                             @"pageSize":@(pageSize),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_SALE_TRADE_LIST parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchSaleTradeYLbListWithPage:(NSInteger)page andPageSize:(NSInteger)pageSize andTimeEnd:(NSString *)timeEnd success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"page":@(page),
                             @"pageSize":@(pageSize),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_SALE_TRADEYLB_LIST parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchSaleTradeListOfMemcacheWithPage:(NSInteger)page andPageSize:(NSInteger)pageSize andTimeEnd:(NSString *)timeEnd success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"page":@(page),
                             @"pageSize":@(pageSize),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_SALE_TRADE_LIST_OF_MEMCACHE parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchSaleTradeYlbListOfMemcacheWithPage:(NSInteger)page andPageSize:(NSInteger)pageSize andTimeEnd:(NSString *)timeEnd success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"page":@(page),
                             @"pageSize":@(pageSize),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_SALE_TRADEYLB_LIST_OF_MEMCACHE parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}




- (void)td_closeTradeWithID:(long long)tid andAlwaysCloseFlag:(BOOL)alwaysCloseFlag success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"id":@(tid),
                             @"isAlwaysClose": alwaysCloseFlag?@"true":@"false",
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_CLOSE_TRADE parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_closeTradeYlbWithID:(long long)tid andAlwaysCloseFlag:(BOOL)alwaysCloseFlag success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"id":@(tid),
                             @"isAlwaysClose": alwaysCloseFlag?@"true":@"false",
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_CLOSE_TRADEYLB parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchTradeSettlementListWithPage:(NSInteger)page andPageSize:(NSInteger)pageSize andTimeEnd:(NSString *)timeEnd success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"page":@(page),
                             @"pageSize":@(pageSize),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_TRADE_SETTLEMENT_LIST parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchTradeYlbSettlementListWithPage:(NSInteger)page andPageSize:(NSInteger)pageSize andTimeEnd:(NSString *)timeEnd success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"page":@(page),
                             @"pageSize":@(pageSize),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_TRADEYLB_SETTLEMENT_LIST parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}



- (void)td_fetchTradeSettlementDetailWithID:(long long)tid success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"strategyId":@(tid),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_TRADE_SETTLEMENT_DETAIL parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchTradeYlbSettlementDetailWithID:(long long)tid success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"strategyId":@(tid),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_TRADEYLB_SETTLEMENT_DETAIL parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchTradeFreeExSettlementDetailWithID:(long long)tid success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"strategyId":@(tid),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_TRADE_FREEEXPERIENCE_SETTLEMENT_DETAIL parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_signTradeAgreementSuccess:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    [self.mainNetwork cq_noCachePOST:URL_FOR_SIGN_AGREEMENT parameters:@{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE} success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchStockAmonutStatisticsWithStockCode:(NSString *)stockCode success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    [self.mainNetwork cq_noCacheGET:URL_FOR_FETCH_STOCK_AMOUNT_STATISTICS parameters:@{@"stockCode":stockCode,COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE} success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
//

- (void)td_fetchYLBStockAmonutStatisticsWithStockCode:(NSString *)stockCode success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure{
    
    [self.mainNetwork cq_noCacheGET:URL_FOR_FETCH_YLBSTOCK_AMOUNT_STATISTICS parameters:@{@"stockCode":stockCode,COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE} success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

@end
